/**
 * 
 */
package com.planner.core.action.node;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.juli.logging.Log;
import org.apache.juli.logging.LogFactory;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.planner.core.action.node.form.NodeDetailForm;
import com.planner.core.action.node.util.NodeDetailFormUtil;
import com.planner.core.vo.GraphNode;

/**
 * @author Sangharsh
 *
 */
public class SaveNodeAction extends AbstractNodeAction {
	
	private static final Log LOG = LogFactory.getLog(SaveNodeAction.class);
	
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		NodeDetailForm detailForm = (NodeDetailForm)form;
		GraphNode node = NodeDetailFormUtil.getNodeVOFromForm(detailForm);
		if(node.getId() == NodeDetailFormUtil.NOT_YET_CREATED_ID.longValue()){
			stopService.add(node);
		}else{
			stopService.updateNode(node);
		}
		
		LOG.info("Executing Action SaveNodeAction"+detailForm);
		return mapping.findForward(SUCCESS_FORWARD);
	}
}
